<html>
<head><meta charset="utf-8"><title>checking that a type is more generic than a different type · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/checking.20that.20a.20type.20is.20more.20generic.20than.20a.20different.20type.html">checking that a type is more generic than a different type</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204359468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/checking%20that%20a%20type%20is%20more%20generic%20than%20a%20different%20type/near/204359468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/checking.20that.20a.20type.20is.20more.20generic.20than.20a.20different.20type.html#204359468">(Jul 19 2020 at 16:49)</a>:</h4>
<p>How can I check that an impl holds for all concrete instantiations of a generic type?</p>



<a name="204359517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/checking%20that%20a%20type%20is%20more%20generic%20than%20a%20different%20type/near/204359517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/checking.20that.20a.20type.20is.20more.20generic.20than.20a.20different.20type.html#204359517">(Jul 19 2020 at 16:50)</a>:</h4>
<p>i.e. I want to return the following in this example:</p>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="204359539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/checking%20that%20a%20type%20is%20more%20generic%20than%20a%20different%20type/near/204359539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/checking.20that.20a.20type.20is.20more.20generic.20than.20a.20different.20type.html#204359539">(Jul 19 2020 at 16:51)</a>:</h4>
<p><code>Vec&lt;()&gt; := true</code>, <code>Vec&lt;U&gt; := true</code>,  <code>Vec&lt;Vec&lt;T&gt;&gt; := true</code>, <code>T := false</code></p>



<a name="204359766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/checking%20that%20a%20type%20is%20more%20generic%20than%20a%20different%20type/near/204359766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/checking.20that.20a.20type.20is.20more.20generic.20than.20a.20different.20type.html#204359766">(Jul 19 2020 at 16:55)</a>:</h4>
<p>To elaborate, I want to get</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(negative_impls)]</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="o">!</span><span class="nb">Send</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">test</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">T</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span>: <span class="nb">Send</span> <span class="p">{</span><span class="w"> </span><span class="n">todo</span><span class="o">!</span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="kt">u8</span> <span class="o">=</span><span class="w"> </span><span class="n">test</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>to compile</p>



<a name="204359980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/checking%20that%20a%20type%20is%20more%20generic%20than%20a%20different%20type/near/204359980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/checking.20that.20a.20type.20is.20more.20generic.20than.20a.20different.20type.html#204359980">(Jul 19 2020 at 16:59)</a>:</h4>
<p>Opened a wip PR for this <a href="https://github.com/rust-lang/rust/issues/74525">#74525</a></p>



<a name="204360435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/checking%20that%20a%20type%20is%20more%20generic%20than%20a%20different%20type/near/204360435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/checking.20that.20a.20type.20is.20more.20generic.20than.20a.20different.20type.html#204360435">(Jul 19 2020 at 17:07)</a>:</h4>
<p>My problem in more detail: <a href="https://github.com/rust-lang/rust/pull/74525/files#r456931789">https://github.com/rust-lang/rust/pull/74525/files#r456931789</a></p>
<blockquote>
<p>So we end up here if we have exactly one impl candidate which is negative.</p>
<p>We only have a negative impl for Foo&lt;()&gt; here, while the self type is actually more generic (Foo&lt;_&gt;).<br>
So if Foo is an auto trait we should return ambiguous in this case, as Foo can be implemented here, e.g. Foo&lt;u8&gt;.</p>
<p>I don't know how we can detect that the impl is at least as general as the current self type rn though, need some help for<br>
this. (I don't think I have to write a new type relation for this thinking )</p>
</blockquote>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>